<!DOCTYPE HTML>
<html lang="en">
<head>
	<meta charset='UTF-8' />
	<meta name='generator' content='ecos.b2c' />
	<title>购物车</title>
	<meta name='keywords' content='' />
	<meta name='description' content='' />
	<meta name='viewport' content='width=device-width, initial-scale=1, maximum-scale=1, user-scalable=no'/>
	<link href="__PUBLIC__/phone/css/zhuce_style.css" rel="stylesheet" media="screen, projection" />
	<script src="__PUBLIC__/phone/js/shop.min.js"></script>
	<link rel="stylesheet" href="__PUBLIC__/phone/css/swiper-3.4.2.min.css" />
	<script src="__PUBLIC__/phone/js/swiper-3.4.2.min.js"></script>
	<style type="text/css">
		.section{
			padding: 8px;
		}
		.d-line .l-k {
			float: none;
		}
		.electrician {
			width: 28%;
			height: 70px;
			border: 1px solid #ccc;
			border-radius: 5px;
			margin-top: 10px;
			text-align: center;
			float: left;
			margin-right: 3%;
			cursor: pointer;
		}
		.xuanred{border: 1px solid red;}
	</style>
</head>
<body style="background-color: #F7F7F8;padding: 0;">
<div class="full-screen">
	<header style="background: #00a1f2;">
		<div class="a-bar">
			<a href="{:U('cart')}" class="a-back">
				<i class="arr left"style="top: 0px;height: 10px;width: 10px;"></i>

			</a>
			<div class="a-name" style="color: white;">
				订单结算
			</div>
		</div>
	</header>
	<form action="{:U('goods_list_zhifu')}" method="post"  class="form" data-type="ajax">
		<input type="hidden" name="cid" value="{$cid}">
		<input type="hidden" name="addr_id" value="{$default_address['address_id']}">
		<input type="hidden" name="count" value="" id="count">
		<input type="hidden" name="diangongid" value="" id="diangongid">
		<a href="{:U('address')}?cid={$cid}">
			<div class="section" style="padding: 6px;height: 60px;" id="J_sel_address" >
				<div style="float: left;height: 100%;width: 15%;text-align: center;">
					<img src="__PUBLIC__/phone/img/map.png" style="max-height: 30px;margin-top: 7px;">
				</div>
				<div style="float: left;height: 100%;width: 45%;text-align: center;">
					<div style="height: 25px;line-height:25px;text-align: start;">
						收货人：<span id="shr">{$default_address.receiver}</span></div>
					<div style="height: 20px;line-height:20px;text-align: start;">
						{$default_address[province_name]}{$default_address[city_name]}{$default_address[county_name]}{$default_address[town_name]}{$default_address[detailed_address]}
					</div>
				</div>
				<div style="float: left;height: 100%;width: 40%;text-align: center;">
					<div style="float: left;">
						<img src="__PUBLIC__/phone/img/phone.png" style="max-height: 30px;margin-top: 7px;">
					</div>
					<div style="float: left;height: 45px;line-height: 45px;text-align: center">
						{$default_address.phone}<i class="arr right" style="left: 2px;border-color: #666"></i>
					</div>
				</div>
			</div>
		</a>

		<div class="" id="cart_main" style="">
			<div class="d-line" style="padding-left: 8px;">
				<span class="k">商品清单：</span>
			</div>
			<!-- 商品清单 -->
			<!-- 购物车条目 -->
			<div class="swiper-container" id="swiper-container3">
				<ul class="swiper-wrapper">
					<volist name="list" id="pic">
						<li class="swiper-slide" style="text-align: center;">
							<img src="__ROOT__{$pic.picture}" style="height: 75px;width: 75px;">
						</li>
					</volist>

				</ul>
			</div>
			<div style="float:right" class="shangping">
				共：<?php echo count($list);?>种<i class="arr right" style="margin:0 8px;border-color: #666"></i>
			</div>

			<ul class="pt-list hide" style="clear: both;">
				<!-- 主商品 -->
				<volist name="list" id="li">
					<li class="pt-h-item c-fix" style="padding: 1px 13px;border-bottom: 1px solid #bfbfbf;">
						<div class="pt-h-img"><img src="__ROOT__{$li.picture}"></div>
						<div class="pt-h-info">
							<a href="/index.php/wap/product-1306.html" class="pt-h-link">
								<div class="pt-h-name">{$li.good_name}</div>
								<div class="pt-h-other"> </div>
								<div class="col2">
									<if condition="session('vip') eq 1">
										<div class="col price">￥{$li.vip_price} </div>
										<else/>
										<div class="col price">￥{$li.price} </div>
									</if>
									<div class="col t-r">数量：{$li.goods_num}</div>
								</div>
							</a>
						</div>
					</li>
				</volist>

			</ul>
			<div class="section" id="checkout_total" style="margin-bottom: 50px;">
				<div class="d-line">
					<span class="k">商品总金额：</span>
			        <span class="v">
			            <div class="price" id="goods-price">￥{$countPrice}</div>
			        </span>
				</div>
			</div>
			<div class="" style="position: fixed;bottom: 0;height: 50px;line-height: 50px;width: 100%;z-index: 9999999;">
				<div style="width: 60%;float: left;background: gainsboro;" class="">
					<span style="padding-left: 10px;">实付款：</span>
					<span style="color: red;font-size: 15px;font-weight: bold" id="kprice">￥{$countPrice}</span><span style="color: red;">元</span>
				</div>
				<div class="" style="float: left;width: 40%;">
					<input type="submit" class="" rel="_request" style="width: 100%;height: 53px;background: red;color: white;" value="订单提交"/>
				</div>
			</div>
		</div>

		<div style="padding: 0 0 60px 10px;">
			<span>是否需要安装</span>
			<input type="checkbox" name="is_install" id="an" value="1" />
			<span style="display: none;">(安装费：￥<span style="color: red;" id="antext">{$count}</span>)</span>

			<div style="margin-top: 20px;display: none;" id="zongelectrician">
				<span style="font-size: 15px;"><b>附近电工</b></span>（选择乡镇并选中电工可实现就近安装，且享受<span style="color:red;"><b>95折</b></span>优惠，否则系统默认派单）：
				<select name="code" id="town" onchange="town_electrician()">
					<option value="">请选择乡/镇</option>
					<volist name="townList" id="vo">
						<option value="{$vo.code}">{$vo.name}</option>
					</volist>
				</select>
				<div id="electrician">

				</div>
			</div>
			<div style="clear: both;"></div>
			<div style="margin-top: 20px;">
				<p>安装费收取标准：</p>
				<p>1）射灯、开关等类似小型部件，按 件收取</p>
				<p>2）除小型部件的其余商品，按其总价的 <b style="color: red;">{$conf.install_price_rebate}</b> 收取</p>
				<p>3）安装费未满<b style="color: red;"> {$conf.min_install_price} </b>元按<b style="color: red;">{$conf.min_install_price}</b>元收取</p>
			</div>
		</div>
	</form>
</div>
<script type="text/javascript">
	//订单商品展示隐藏
	$('.shangping').on('click',function() {
		if ($('.pt-list').hasClass('hide')){
			$('.pt-list').removeClass('hide');
		}else {
			$('.pt-list').addClass('hide');
		}
	});

	/**
	 * 除法函数，用来得到精确的除法结果 说明：javascript的除法结果会有误差，在两个浮点数相除的时候会比较明显。这个函数返回较为精确的除法结果。
	 * 调用：accDiv(arg1,arg2) 返回值：arg1除以arg2的精确结果
	 */
	function accDiv(arg1,arg2){
		var t1=0,t2=0,r1,r2;
		try{t1=arg1.toString().split(".")[1].length}
		catch(e){}
		try{t2=arg2.toString().split(".")[1].length}
		catch(e){}
		with(Math){
			r1=Number(arg1.toString().replace(".",""));
			r2=Number(arg2.toString().replace(".",""));
			return (r1/r2)*pow(10,t2-t1);
		}
	}


	/**
	 * javascript的乘法结果会有误差，在两个浮点数相乘的时候会比较明显。这个函数返回较为精确的乘法结果。
	 *
	 *
	 */
	function accMul(arg1,arg2){
		var m=0,s1=arg1.toString(),s2=arg2.toString();
		try{m+=s1.split(".")[1].length}catch(e){}
		try{m+=s2.split(".")[1].length}catch(e){}
		return Number(s1.replace(".",""))*Number(s2.replace(".",""))/Math.pow(10,m);
	}

	//点击是否安装
	$('#an').click(function () {
		var goodsprice = parseFloat($("#goods-price").text().substring(1))
		var antext = parseFloat($('#antext').text())
		var kprice = parseFloat($("#kprice").text().substring(1))
		if($(this).is(':checked')){
			$("#zongelectrician").show()
			$(this).next().show()
			$('#kprice').text((goodsprice+antext))
		}else{
			$("#zongelectrician").hide()
			$(this).next().hide()
//			$('#kprice').text('￥'+parseFloat(parseFloat(kprice)-parseFloat(antext)).toFixed(2))
			$('#kprice').text('￥'+parseFloat(goodsprice).toFixed(2))
			$('#count').val('');
			$('#kprice').removeAttr('data-money')
		}
	})

	$(document).on('click','#electrician>div',function(){
		if($(this).is('.xuanred')){
			$(this).removeClass('xuanred')
			$('#kprice').removeAttr('data-money')
			$('#kprice').text(accDiv(parseFloat($('#kprice').text()),0.95))
			$('#count').val($('#kprice').text())
			$('#diangongid').val("")
		}else{
			$(this).addClass('xuanred').siblings().removeClass('xuanred')
			if(!$('#kprice').attr('data-money')){
				$('#kprice').text(accMul(parseFloat($('#kprice').text()),0.95))
				$('#count').val($('#kprice').text())
				$('#kprice').attr('data-money','1')
			}
			$('#diangongid').val($(this).attr('data-value'))
		}

	})
</script>
<script>
	//获取所在乡镇电工
	function town_electrician(){
		$('.loading').show();
		//获取被选中的option标签
		var town = $('#town option:selected').val();
		//ajax获取专题下的一级分类
		$.ajax({
			url:"{:U('town_electrician_list')}",
			type:'post',
			async: false,
			data:{town:town},
			success:function(data){
				$('.loading').hide();
				var electrician_list = JSON.parse(data);
				if(electrician_list.length == 0){
					alert('该乡镇暂无电工注册');
				}
				$('#diangongid').val("")
				$('#kprice').removeAttr('data-money')
				$('#kprice').text(parseFloat("{$countPrice}")+parseFloat($('#antext').text()))
				$('#count').val($('#kprice').text())
				var aa = '';
				for(var i=0;i<electrician_list.length;i++){
					aa += '<div class="electrician" data-value="'+electrician_list[i].electrician_id+'">'
							+'<div style="margin-top: 16px;"><span>'+electrician_list[i].real_name+'</span></div>'
							+'<div><span>'+electrician_list[i].phone+'</span></div>'
							+'</div>'
				}
				$('#electrician').html(aa);
			}
		})
	}
</script>
<script>
	var swiper1 = new Swiper('#swiper-container3', {
		autoplay:3000,
		slidesPerView: 4,
		slidesPerColumn: 1,
		spaceBetween: 0,
		freeMode: false,

	});
</script>
</body>
</html>